package uml.view.factory;

import java.awt.Point;
import java.awt.Stroke;
import java.util.ArrayList;

import uml.eventsystem.events.UMLEventId;
import uml.objects.AnchorPoint;
import uml.objects.ArrowEnd;
import uml.objects.UMLObject;
import uml.util.UMLConstants;

/**
 * A factory class that creates UML relationship objects. The methods of this 
 * class return formatted base <tt>RelationshipArrow</tt> objects 
 * that represent different UML relationships. 
 * 
 * @author Neil Obetz
 *
 */

public final class RelationshipArrowFactory
{
	/**
	 * Creates and formats an association
	 * @return 
	 * 
	 * @return the association object
	 */
	
	/**
	 * A filter method for users to invoke when a
	 * UMLObject creation event is invoked  
	 * 
	 * @param eventId the event that occurred
	 * @return the object requested
	 */
	
	public static UMLObject createObject (UMLEventId eventId)
	{
		UMLObject obj = null;
		
		
		if (eventId.equals (UMLEventId.MAKE_ASSOCIATION))
		{
			obj = createRelationship (UMLConstants.DASHED_LINE, UMLConstants.NO_END, UMLConstants.BLACK_ARROW_HEAD, listOfPoints () );
		}
		else if (eventId.equals (UMLEventId.MAKE_COMPOSITION))
		{
			obj = createRelationship (UMLConstants.REGULAR_LINE, UMLConstants.BLACK_DIAMOND, UMLConstants.BLACK_ARROW_HEAD, listOfPoints () );
		}
		else if (eventId.equals (UMLEventId.MAKE_AGGREGATION))
		{
			obj = createRelationship (UMLConstants.REGULAR_LINE, UMLConstants.WHITE_DIAMOND, UMLConstants.BLACK_ARROW_HEAD, listOfPoints () );
		}
		else if (eventId.equals (UMLEventId.MAKE_GENERALIZATION))
		{
			obj = createRelationship (UMLConstants.REGULAR_LINE, UMLConstants.NO_END, UMLConstants.WHITE_ARROW_HEAD, listOfPoints () );
		}
		else
		{
			System.out.println ("Not a valid id. Returning a default value.");
		}
		if(obj != null)
			obj.setEventId(eventId);
		
		return obj;
	}
	
	/**
	 * General method that creates all the types of arrows we need
	 * @param color arrow color.
	 * @param stroke arrow stroke
	 * @param front ArrowEnd for the front of arrow
	 * @param end  ArrowEnd the back of arrow
	 * @param points an array of points to use as anchor points
	 * @return the relationship arrow
	 */
	
	public static AnchorPoint createRelationship (Stroke stroke, ArrowEnd front, ArrowEnd end, ArrayList<Point> points)
	{
		AnchorPoint start = new AnchorPoint(UMLConstants.ARROW_START_LOCATION, null, stroke, front);
		AnchorPoint endPoint = new AnchorPoint(UMLConstants.ARROW_END_LOCATION, null, stroke, end);
		start.addSibling(endPoint);
		return start;
		
		//return new ArrowLink(UMLConstants.ARROW_START_LOCATION, UMLConstants.ARROW_END_LOCATION, stroke, front, end);
	}

	private static ArrayList<Point> listOfPoints ()
	{
		ArrayList<Point> list = new ArrayList <Point> ();
		list.add (new Point (20, 20));
		list.add (new Point (50, 50));
		list.add (new Point (100, 100));
		list.add (new Point (150, 150));
		return list;
	}
}
